using FreeSql.DataAnnotations;

namespace SumerCoreDevOps.Domain.Entities;

/// <summary>
/// 主节点实体，用于记录控制面板主节点信息
/// </summary>
[Table(Name = "master_nodes")]
[Index("idx_master_id", nameof(MasterId), true)]
[Index("idx_is_online", nameof(IsOnline), false)]
[Index("idx_last_heartbeat", nameof(LastHeartbeatTime), false)]
public class MasterNode
{
    /// <summary>
    /// 主键ID
    /// </summary>
    [Column(IsIdentity = true, IsPrimary = true)]
    public long Id { get; set; }

    /// <summary>
    /// 主节点唯一标识符
    /// </summary>
    [Column(StringLength = 64, IsNullable = false)]
    public string MasterId { get; set; } = string.Empty;

    /// <summary>
    /// 主机地址
    /// </summary>
    [Column(StringLength = 255, IsNullable = false)]
    public string Host { get; set; } = string.Empty;

    /// <summary>
    /// TCP 端口
    /// </summary>
    [Column(IsNullable = false)]
    public int TcpPort { get; set; }

    /// <summary>
    /// API 端口
    /// </summary>
    [Column(IsNullable = false)]
    public int ApiPort { get; set; }

    /// <summary>
    /// 是否在线
    /// </summary>
    [Column(IsNullable = false)]
    public bool IsOnline { get; set; }

    /// <summary>
    /// 最后心跳时间
    /// </summary>
    [Column(IsNullable = true)]
    public DateTime? LastHeartbeatTime { get; set; }

    /// <summary>
    /// 创建时间
    /// </summary>
    [Column(IsNullable = false, ServerTime = DateTimeKind.Local)]
    public DateTime CreatedAt { get; set; } = DateTime.Now;

    /// <summary>
    /// 更新时间
    /// </summary>
    [Column(IsNullable = false, ServerTime = DateTimeKind.Local)]
    public DateTime UpdatedAt { get; set; } = DateTime.Now;
}
